//
//  SISSMapManager.m
//  SISSAPP
//
//  Created by 袁应荣 on 06/06/2017.
//  Copyright © 2017 优房网. All rights reserved.
//

#import "SISSMapManager.h"
#import "SISSMapViewController.h"
#import "SISSHousePriceMapViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <BaiduMapAPI_Map/BMKMapView.h>

@implementation SISSMapManager

+ (void)disposeGeocoderWithMapVC:(SISSMapViewController *)mapViewController zoomValue:(NSInteger)zoomValue {
    
    //创建编码对象
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:mapViewController.region completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        if (error != nil || placemarks.count == 0) {
            return;
        }
        //创建placemark对象
        CLPlacemark *placemark = [placemarks firstObject];
        NSLog(@"%f,%f",placemark.location.coordinate.latitude,placemark.location.coordinate.longitude);
        //赋值详细地址
        NSLog(@"详细地址 %@",placemark.name);
        CLLocationCoordinate2D coor;
        coor.latitude = placemark.location.coordinate.latitude;
        coor.longitude = placemark.location.coordinate.longitude;
        [mapViewController.mapView setCenterCoordinate:coor];
        [mapViewController.mapView setZoomLevel:zoomValue];
        mapViewController.zoomValue = zoomValue;
    }];

}

+ (void)disposeGeocoderWithHousePriceMapVC:(SISSHousePriceMapViewController *)mapViewController zoomValue:(NSInteger)zoomValue {
    
    //创建编码对象
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:mapViewController.region completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        if (error != nil || placemarks.count == 0) {
            return;
        }
        //创建placemark对象
        CLPlacemark *placemark = [placemarks firstObject];
        NSLog(@"%f,%f",placemark.location.coordinate.latitude,placemark.location.coordinate.longitude);
        //赋值详细地址
        NSLog(@"详细地址 %@",placemark.name);
        CLLocationCoordinate2D coor;
        // 为更好展示地图效果，稍微调整地图中心经纬度
        coor.latitude = placemark.location.coordinate.latitude + 0.09;
        coor.longitude = placemark.location.coordinate.longitude;
        [mapViewController.mapView setCenterCoordinate:coor];
        [mapViewController.mapView setZoomLevel:zoomValue];
        mapViewController.zoomValue = zoomValue;
    }];
    
}

@end
